﻿namespace Borg.AddOn
{
    internal sealed class ActivatorSubstitutionHookChain : IActivatorSubstitutionHook
    {
        private readonly IActivatorSubstitutionHook[] _substitutionHooks;

        public ActivatorSubstitutionHookChain(IActivatorSubstitutionHook[] substitutionHooks)
        {
            _substitutionHooks = substitutionHooks;
        }

        public bool Create(Extension extension, out object obj)
        {
            foreach (IActivatorSubstitutionHook hook in _substitutionHooks)
                if (hook.Create(extension, out obj))
                    return true;

            obj = null;
            return false;
        }

        public void SubstituteExtensionObject(Extension extension, ref object obj)
        {
            foreach (IActivatorSubstitutionHook hook in _substitutionHooks)
                hook.SubstituteExtensionObject(extension, ref obj);
        }
    }
}
